home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
Tracer.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
3KB
|
101 lines
" NAME Tracer
AUTHOR ikp@cs.man.ac.uk
FUNCTION displays msg-sends to a particular object
ST-VERSIONS 2.2
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE 22 Jan 1989
SUMMARY Tracer
is a simple tracing mechanism which displays message sends to
an object, and the results returned.(2.2). IKP
"!
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 18 December 1987 at 7:48:44 am'!
Object subclass: #Tracer
instanceVariableNames: 'object recorder '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Debugger'!
!Tracer methodsFor: 'message handling'!
doesNotUnderstand: aMessage
"trace the selector then pass the message on"
| result |
recorder nextPutAll: object class printString; nextPutAll: '['; nextPutAll: aMessage selector asString.
aMessage arguments size = 0
ifTrue:
[result _ object perform: aMessage selector]
ifFalse:
[recorder nextPutAll: aMessage arguments printString.
result _ object perform: aMessage selector withArguments: aMessage arguments].
recorder nextPutAll: ']^'; nextPutAll: result printString; cr.
recorder class == TextCollector ifTrue: [recorder endEntry].
^result! !
!Tracer methodsFor: 'accessing'!
setTracerObjectTo: newObject recordingOn: aStreamOrTranscript
"change the object which I trace, and the stream I record on. Hopefully a suitably obscure selector!!"
object _ newObject.
recorder _ aStreamOrTranscript! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
Tracer class
instanceVariableNames: ''!
!Tracer class methodsFor: 'class initialization'!
initialize
"Remove my superclass pointer. All messages to me will then generate 'doesNotUnderstand'"
superclass _ nil
"Tracer initialize"! !
!Tracer class methodsFor: 'instance creation'!
on: anObject
"open a tracer on anObject"
^self new setTracerObjectTo: anObject recordingOn: Transcript!
on: anObject loggedOn: aStream
"open a tracer on anObject, recording messages on aStream"
^self new setTracerObjectTo: anObject recordingOn: aStream! !
!Tracer class methodsFor: 'examples'!
example1
"demonstrate a simple trace. must have a transcript handy!!"
"Tracer example1" "<--- click on `Print It'"
| anArray |
anArray _ Tracer on: (Array new: 3).
anArray at: 2 put: 'hello'.
^anArray size!
example2
"demonstrate a simple trace, logged on a stream."
"Tracer example2" "<--- click on `Print It'"
| anArray aStream |
aStream _ ReadWriteStream on: ''.
anArray _ Tracer on: (Array new: 3) loggedOn: aStream.
anArray at: 2 put: 'hello'.
anArray at: 2.
anArray printString.
^aStream contents! !
Tracer initialize!